from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
from meiduo_mall import settings
#定义加密和解密
def generic_access_token(openid):
    s=Serializer(secret_key=settings.SECRET_KEY,expires_in=3600)
    token = s.dumps({'openid':openid})
    return token.decode() #需要解码


def check_access_token(token):
    s = Serializer(secret_key=settings.SECRET_KEY, expires_in=3600)
    try:
        result=s.loads(token)

    except Exception:
        return None
    return result.get('openid')



